{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Rational Interpolation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Should be a better interpolation method that causes less errors with time-domain transformations.\n",
    "\n",
    "Based on: https://www.in.tu-clausthal.de/fileadmin/homes/techreports/ifi0606floater.pdf\n",
    "\n",
    "Example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import skrf\n",
    "import matplotlib.pyplot as plt\n",
    "from skrf.plotting import stylely\n",
    "from skrf.media import Coaxial\n",
    "\n",
    "%matplotlib inline\n",
    "stylely()\n",
    "\n",
    "freq = skrf.F(0.5,110,801)\n",
    "freq2 = skrf.F(0,110,801)\n",
    "coax1mm = Coaxial(freq, z0=50, Dint=0.44e-3, Dout=1.0e-3, sigma=1e20)\n",
    "coax1mm2 = Coaxial(freq2, z0=50, Dint=0.44e-3, Dout=1.0e-3, sigma=1e20)\n",
    "\n",
    "X = coax1mm.line(10, 'mm', z0=50, name='X', embed=True)\n",
    "Y = coax1mm.line(80, 'mm', z0=75, name='Y', embed=True)\n",
    "dut = X**Y**X\n",
    "\n",
    "X2 = coax1mm2.line(10, 'mm', z0=50, name='X', embed=True)\n",
    "Y2 = coax1mm2.line(80, 'mm', z0=75, name='Y', embed=True)\n",
    "dut2 = X2**Y2**X2\n",
    "dut2.name = 'real'\n",
    "\n",
    "dut_dc_rational = dut.extrapolate_to_dc(kind='rational', dc_sparam=[[0,1],[1,0]])\n",
    "dut_dc_rational.name = 'rationnal'\n",
    "dut_dc_linear = dut.extrapolate_to_dc(kind='linear', dc_sparam=[[0,1],[1,0]])\n",
    "dut_dc_linear.name = 'linear'\n",
    "dut_dc_cubic = dut.extrapolate_to_dc(kind='cubic', dc_sparam=[[0,1],[1,0]])\n",
    "dut_dc_cubic.name = 'cubic'\n",
    "\n",
    "plt.figure()\n",
    "plt.title('Step Response Lowpass')\n",
    "dut2.s11.plot_s_time_step(pad=2000, window='hamming')\n",
    "dut_dc_rational.s11.plot_s_time_step(pad=2000, window='hamming')\n",
    "dut_dc_linear.s11.plot_s_time_step(pad=2000, window='hamming')\n",
    "dut_dc_cubic.s11.plot_s_time_step(pad=2000, window='hamming')\n",
    "\n",
    "plt.figure()\n",
    "plt.title('Impulse Response Lowpass')\n",
    "dut2.s11.plot_s_time_impulse(pad=2000, window='hamming')\n",
    "dut_dc_rational.s11.plot_s_time_impulse(pad=2000, window='hamming')\n",
    "dut_dc_linear.s11.plot_s_time_impulse(pad=2000, window='hamming')\n",
    "dut_dc_cubic.s11.plot_s_time_impulse(pad=2000, window='hamming')\n",
    "\n",
    "plt.figure()\n",
    "plt.title('Impulse Response Bandpass')\n",
    "dut2.s11.plot_s_time(pad=2000, window='hamming')\n",
    "(dut_dc_rational.s11.windowed()).plot_s_time()\n",
    "(dut_dc_linear.s11.windowed()).plot_s_time()\n",
    "(dut_dc_cubic.s11.windowed()).plot_s_time()\n",
    "\n",
    "plt.show(block=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
